package com.bytecodezz.app.base.extend.function

import android.content.Context

/**
 * @author: bytecodezz
 * @version: 1.0
 * @time: 2021/9/15 13:50
 * @package: com.bytecodezz.app.base.extend.function
 *
 * @description:
 *
 */
fun Context.dp2px(dp: Int): Int {
    return dp2px(dp.toFloat()).toInt()
}

fun Context.dp2px(dp: Float): Float {
    return resources.displayMetrics.density * dp + 0.5f
}

fun Context.px2dp(px: Int): Int {
    return px2Dp(px.toFloat()).toInt()
}

fun Context.px2Dp(px: Float): Float {
    val fontScale: Float = resources.displayMetrics.scaledDensity
    return px / fontScale + 0.5f
}